package kk.yy.myaccount.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.angmarch.views.NiceSpinner;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import kk.yy.myaccount.R;

public class AccountDialog extends Dialog {
    private EditText priceEt;
    private NiceSpinner niceSpinner;
    private Button addBtn;

    public AccountDialog(Context context) {
        super(context, R.style.CustomDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_account_dialog);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面控件的事件
        initEvent();
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {

        addBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ( onClickBottomListener!= null) {
                    onClickBottomListener.onPositiveClick();
                }
            }
        });

    }



    @Override
    public void show() {
        super.show();
    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        addBtn = (Button) findViewById(R.id.add_btn);
        niceSpinner = (NiceSpinner) findViewById(R.id.nice_spinner);
        priceEt = (EditText) findViewById(R.id.title);
        List<String> dataset = new LinkedList<>(Arrays.asList("One", "Two", "Three", "Four", "Five"));
        niceSpinner.attachDataSource(dataset);
    }

    /**
     * 设置确定取消按钮的回调
     */
    public OnClickAddListener onClickBottomListener;
    public AccountDialog setOnClickBottomListener(OnClickAddListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        return this;
    }
    public interface OnClickAddListener{
        /**
         * 点击确定按钮事件
         */
        public void onPositiveClick();
    }



}